<?php
define('ACTION_ADDFRIEND', 'add');
define('ACTION_DELETEFRIEND', 'del');
define('ACTION_LISTFRIENDS', 'list');

switch(true){
	case (strcmp($action, ACTION_ADDFRIEND) == 0):
		if(!empty($_GET['friend']) && is_string($_GET['friend']) && (strcmp($_GET['friend'], $user->getEmail()) != 0)){
			$friendMail = $_GET['friend'];
			$friendUser = new User();
			if($friendUser->getUserByMail($friendMail)) {				
				$user->addFriend($friendUser);
				$result = array('status' => NO_ERR, 'result' => $friendUser->tojson()); // Error? y resultado
			} else {
				$result = array('status' => ERR_USER_NOTEXISTS);
			}
		} else {
			$result = array('status' => ERR_GENERAL);			
		}
		break;
	case (strcmp($action, ACTION_DELETEFRIEND) == 0):
		if(!empty($_GET['friend']) && is_string($_GET['friend'])){
			$friendMail = $_GET['friend'];
			$friendUser = new User();
			if($friendUser->getUserByMail($friendMail)) {
				$user->deleteFriend($friendUser->getId());
				
				$result = array('status' => NO_ERR);
			} else {
				$result = array('status' => ERR_USER_NOTEXISTS);
			}
		} else {
			$result = array('status' => ERR_GENERAL);
		}
		break;
	case (strcmp($action, ACTION_LISTFRIENDS) == 0):
		$result = $user->listFriends();
		
		$result = array('status' => NO_ERR, 'result' => $result);
		break;
	default:
		$result = array('status' => ERR_GENERAL);
}


?>